<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>委外催收分案</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <form id = "formSet" class="l-form">
            <div id="ligergrid1" class="sq-grid"></div>
            <div class="btnsBox">
                <span class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_10"></i>委案</span>
            </div>
        </form>
        <div id="ligergrid2" class="sq-grid"></div>
    </div>
</div>
</body>

<script type="text/javascript">
    var grid1 = null,grid2 = null, menu = null;
    $(function () {
        var cstId='${cstId}';
        var paySchId = '${paySchId}';
        var selectAuthDays = [
            { "text": "90", "authDay": 90 },
            { "text": "120", "authDay": 120 },
            { "text": "180", "authDay": 180 }
        ];
        var authOrgCdList = ${authOrgCdList};
        //[{"chg":false,"crtTm":1560829139572,"crtUsrId":1,"id":190618165006547,"isDel":0,"isSysDef":0,"isValid":0,"mdfTm":1560829139000,"mp":"13958215059","refId":190618169006727,"refIsDel":0,"refIsSysDef":0,"refIsValid":1,"refLockState":0,"refPwd":"96e79218965eb72c92a549dd5a330112","refRegDt":1560829139573,"refRegTypCd":"1","refRlNm":"tb","refSysCd":"11000","regChlCd":"11001","usrNm":"1004097","usrTypCd":"2"},{"chg":false,"crtTm":1535965479069,"crtUsrId":1,"id":180903165001604,"isDel":0,"isSysDef":0,"isValid":1,"mp":"15203111942","refId":180903169001625,"refIsDel":0,"refIsSysDef":0,"refIsValid":1,"refLockState":0,"refPwd":"e10adc3949ba59abbe56e057f20f883e","refRegDt":1535965479069,"refRegTypCd":"1","refRlNm":"陈金","refSysCd":"11000","regChlCd":"11001","usrNm":"1003154","usrTypCd":"1"},{"chg":false,"crtTm":1532917615628,"crtUsrId":1,"id":180730165001415,"isDel":0,"isSysDef":0,"isValid":1,"refId":180730169001435,"refIsDel":0,"refIsSysDef":0,"refIsValid":1,"refLockState":0,"refPwd":"96e79218965eb72c92a549dd5a330112","refRegDt":1532917615629,"refRegTypCd":"1","refRlNm":"陈苓","refSysCd":"11000","regChlCd":"11001","usrNm":"1002912","usrTypCd":"1"},{"chg":false,"crtTm":1494943660000,"crtUsrId":1,"id":3,"isDel":0,"isSysDef":1,"isValid":1,"refId":170506001,"refIsDel":0,"refIsSysDef":1,"refIsValid":1,"refLockState":0,"refPwd":"96e79218965eb72c92a549dd5a330112","refRegDt":1494943662000,"refRegTypCd":"1","refRlNm":"系统审核","refSysCd":"11000","regChlCd":"11001","usrNm":"aud","usrTypCd":"1"},{"chg":false,"crtTm":1483902514000,"crtUsrId":1,"id":1000144,"isDel":0,"isSysDef":0,"isValid":1,"mp":"13930422010","refId":10145,"refIsDel":0,"refIsSysDef":0,"refIsValid":1,"refLockState":0,"refPwd":"96e79218965eb72c92a549dd5a330112","refRegDt":1483902516000,"refRegTypCd":"1","refRlNm":"周伟静","refSysCd":"11000","regChlCd":"11001","usrNm":"1000073","usrTypCd":"1"},{"chg":false,"crtTm":1483902513000,"crtUsrId":1,"id":1,"isDel":0,"isSysDef":1,"isValid":1,"mdfTm":1561951744125,"mdfUsrId":1,"mp":"13801211380","refId":10000,"refIsDel":0,"refIsSysDef":1,"refIsValid":1,"refLockState":0,"refPwd":"dab2991d3c965baf026b5f374a63c3ca","refPwdCrtTm":1586506992000,"refRegDt":1483902515000,"refRegTypCd":"1","refRlNm":"admin","refSalt":"abcdef","refSysCd":"11000","regChlCd":"11001","usrNm":"admin","usrTypCd":"1"},{"chg":false,"crtTm":1483902513000,"crtUsrId":1,"id":1000136,"isDel":0,"isSysDef":0,"isValid":1,"mp":"18503110806","refId":10137,"refIsDel":0,"refIsSysDef":0,"refIsValid":1,"refLockState":0,"refPwd":"57eb0057406c7ad2f37f59f7b445c157","refPwdCrtTm":1583395932000,"refRegDt":1483902516000,"refRegTypCd":"1","refRlNm":"许俊华","refSalt":"e55c","refSysCd":"11000","regChlCd":"11001","usrNm":"1000078","usrTypCd":"1"}]
        grid1 = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/clt/auth/rskCltAuth/getRskCltAuthByPaySchId.do?cstId=' + cstId + '&paySchId='+ paySchId,
            method : 'get',
            columns: [
                {display: '委案开始时间', name: 'startDate', minWidth: 100, align: 'left', enabledSort: false,render: renderDate},
                {display: '委案结束时间', name: 'endDate', minWidth: 100, align: 'left', enabledSort: false,render: renderDate},
                {
                    display: '<span class="requiredSymbol">*</span>委案天数', name: 'authDays', minWidth: 100, hide: false,
                    valueField: 'authDays',
                    textField: 'text',
                    editor: {
                        type: 'select',
                        data: selectAuthDays,
                        valueField: 'authDay',
                        textField: 'text',
                        onSelected: function (a,b) {
                            addTime(a);
                        }
                    },
                    render: function (item)
                    {
                        if(item.authDays != null){
                            return item.authDays;
                        }
                        return item.authDaysStr;
                    }
                },
                {
                    display: '<span class="requiredSymbol">*</span>委案机构', name: 'authOrgCd', minWidth: 100, hide: false,
                    valueField: 'authOrgCd',
                    textField: 'authOrgCdNm',
                    editor: {
                        type: 'select',
                        data: authOrgCdList,
                        valueField: 'id',
                        textField: 'refRlNm',
                        onSelected: function (a,b) {
                        }
                    },
                    render: function (item)
                    {
                        return item.authOrgCdNm;
                    }
                },
                {display: '剩余租金', name: 'residualRent', width: 90, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.residualRent/100);
                    }},
                {display: '应收金额', name: 'arAmt', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.arAmt/100);
                    }
                },
                {display: '违约金', name: 'breachAmt', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.breachAmt/100);
                    }
                },
                {display: '委案金额', name: 'authAmt', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.authAmt/100);
                    }
                },

            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '40%',
            heightDiff: -2,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            usePager: false,
            enabledEdit: true
        });
        grid2 = $("#ligergrid2").ligerGrid({
            url: '<%=path%>/clt/auth/rskCltAuth/initRskCltAuthList.do?paySchId='+ paySchId +'&cstId='+cstId,
            method : 'get',
            columns: [
                {display: '委案开始时间', name: 'startDate', minWidth: 80, align: 'center', enabledSort: false, render: renderDate},
                {display: '委案结束时间', name: 'endDate', minWidth: 80, align: 'center', enabledSort: false, render: renderDate},
                {display: '委案机构', name: 'authOrgCd', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return rowdata.authOrgCdNm;
                    }},
                {display: '委案金额', name: 'authAmt', width: 90, align: 'center', enabledSort: false,render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.authAmt/100);
                    }
                },
                {display: '回款金额', name: 'recoveryAmt', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.recoveryAmt/100);
                    }
                },
                {display: '违约金', name: 'breachAmt', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.breachAmt/100);
                    }
                },
                {
                    display: '历史委案状态', name: 'authStsCd', minWidth: 80, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value) {
                        var authStsCd = rowdata.authStsCd == null ? " " : rowdata.authStsCd;
                        if (authStsCd == '0') {
                            var h = '';
                            h += '<a href="javascript:backoutRskCltAuth(';
                            h += "'" + rowdata.id + "'";
                            h += ')">撤案</a>';
                            return "委案中." + h;
                        }else if(authStsCd == '1'){
                            return "已撤案";
                        }else if(authStsCd == '2'){
                            return "已到期";
                        }else if(authStsCd == '3'){
                            return "已退案";
                        }

                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true
        });

        $("#formSet").ligerForm();
        $("#formSet .l-dialog-btn-ok").click(function(event) {
            var targetRow = grid1.rows[0];
            //top.$.ligerDialog.SQalert({SQ_type: "warning",content: "不能为空！"});
            var authOrgCd = targetRow.authOrgCd;
            var authDays = targetRow.authDays;
            if(authOrgCd == undefined || authOrgCd == ''){
                top.$.ligerDialog.SQalert({content:"委案机构不能为空!",SQ_type: "warning"});
                return;
            }
            if(authDays == undefined || authDays == ''){
                top.$.ligerDialog.SQalert({content:"委案天数不能为空!",SQ_type: "warning"});
                return;
            }
            $.ajax({
                type: 'post',
                dataType:'json',
                data:targetRow,
                url: '<%=path%>/clt/auth/rskCltAuth/add.do',
                success:function(msg){
                    if(msg.success == 1){
                        top.$.ligerDialog.SQalert({content: "委案成功！",SQ_type: "success"});
                        //grid2.reload();
                        parent.grid.reload();
                        frameElement.dialog.close();
                    }else{
                        top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});

                    }
                }
            });
        });

    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && '' != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
        var h = "￥" + FormatMoney(value);
        return h;
    }

    function addTime(day){
        if(day == "" || day == "请选择"){
            var targetRow = grid1.rows[0];
            grid1.updateCell('endDate','', targetRow);
            return;
        }
        $.ajax({
            type: 'get',
            dataType:'json',
            data:{},
            url: '<%=path%>/clt/auth/rskCltAuth/addTime.do?day='+day,
            success:function(msg){
                if(msg.success == 1){
                    var targetRow = grid1.rows[0];
                    grid1.updateCell('endDate',msg.data, targetRow);
                    //targetRow.endDate = msg.data;
                }
            }
        });
    }

    function backoutRskCltAuth(id){
        $.ligerDialog.confirm("撤案之后催收机构将无法查看已撤案记录,是否确认撤案?", function (flag) {
            if (flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {id: id,authStsCd:"1"},
                url: '<%=path%>/clt/auth/rskCltAuth/modify.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: "撤案成功!",SQ_type: "success"});
                        //grid2.reload();
                        //grid1.reload();
                        parent.grid.reload();
                        frameElement.dialog.close();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
</script>
</html>
